// export { default } from './index.vue';

import { h, render } from 'vue';
import Index from './index.vue';

export const Confirm = ({
  title,
  content,
  confirmText,
  cancelText
}: {
  title: string;
  content: string;
  confirmText: string;
  cancelText: string;
}) => {
  if (title && !content) {
    content = title;
    title = '';
  }

  return new Promise<void>((resolve, reject) => {
    const close = () => {
      render(null, document.body);
    };
    const confirmHandler = () => {
      resolve();
    };
    const cancelHandler = () => {
      reject(new Error('点击取消按钮'));
    };

    const VNode = h(Index, {
      title,
      content,
      confirmText,
      cancelText,
      confirmHandler,
      cancelHandler,
      close
    });

    render(VNode, document.body);
  });
};
